<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\logic;

/**
 * 友情链接逻辑
 */
class Kafrom extends AdminBase
{
    
    /**
     * 获取友情链接列表
     */
    public function getKafromList($where = [], $field = true, $order = '', $paginate = 0)
    {
         if(session('member_info')['id']!=1){
             $where['name']=session('member_info')['username'];
       }
        return $this->modelKafrom->getList($where, $field, $order, $paginate);
    }
    
    /**
     * 友情链接信息编辑
     */
    public function kafromEdit($data = [])
    {
        
        // $validate_result = $this->validateKafrom->scene('edit')->check($data);
        
        // if (!$validate_result) {
            
        //     return [RESULT_ERROR, $this->validateKafrom->getError()];
        // }
        
        $url = url('kafromList');
         $data['status']=3;
        $result = $this->modelKafrom->setInfo($data);
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, '友情链接' . $handle_text . '，name：' . $data['name']);
        
        return $result ? [RESULT_SUCCESS, '操作成功', $url] : [RESULT_ERROR, $this->modelKafrom->getError()];
    }

    /**
     * 获取友情链接信息
     */
    public function getKafromInfo($where = [], $field = true)
    {
        
        return $this->modelKafrom->getInfo($where, $field);
    }
    
    /**
     * 友情链接删除
     */
    public function kafromDel($where = [])
    {
        
        $result = $this->modelKafrom->deleteInfo($where);
        
        $result && action_log('删除', '友情链接删除' . '，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '删除成功'] : [RESULT_ERROR, $this->modelKafrom->getError()];
    }


     public function kafromxg($where = [])
    {

        $where["status"]=1;
        $result = $this->modelKafrom->setInfo($where);
        
        $result && action_log('删除', '友情链接删除' . '，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '修改成功'] : [RESULT_ERROR, $this->modelKafrom->getError()];
    }
    public function kafromwtg($data = [])
    {
        $data['time']=time();
    

        $url = url('kafromList');
         $data['status']=0;
        $result = $this->modelKafrom->setInfo($data);
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, '友情链接' . $handle_text . 'id' . $data['id']);
        
        return $result ? [RESULT_SUCCESS, '操作成功', $url] : [RESULT_ERROR, $this->modelKafrom->getError()];
    }





     public function kafromsq($id=''){
          $where['id']=$id;
    
           $a=$this->modelKkt->getInfo($id);
           return $a;
        
     }
}
